#include <stdio.h>

#define SHM_QUEUE_IMPLEMENTATION
#define SHM_NOTIFY_IMPLEMENTATION

#if _WIN32
#include "shm_queue_win.h"
#include "shm_notify_win.h"
#else
#include "shm_queue_linux.h"
#include "shm_notify_linux.h"
#endif

int main() {
  shm_notify_t rnotify;
  shm_queue_t rqueue;
  shm_queue_options_t options;
  options.elem_count = 128;
  options.elem_size = 1024;
  options.mode = SHM_QUEUE_MODE_READ | SHM_QUEUE_MODE_CREATE;
  options.name = "test";

  int rslt = shm_queue_open(&rqueue, &options);
  printf("shm_queue_open ret:%d\n", rslt);

  rslt = shm_notify_open(&rnotify, "TestNotify");
  printf("shm_notify_open ret:%d\n", rslt);


  char buffer[1024];

  while (1) {
    rslt = shm_queue_read(&rqueue, buffer, sizeof(buffer));
    if (rslt >= 0) {
      printf("shm_queue_read msgid:%d size:%d \n", rqueue.rmsgid, rslt);
    } else {
      shm_notify_wait(&rnotify, 1000);
    }
  }
  printf("finish\n");
  shm_queue_close(&rqueue);
  return 0;
}
